<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for utils.js</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="prettify.css" />
    <link rel="stylesheet" href="base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="index.html">All files</a> utils.js
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">98.21% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>55/56</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">94.29% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>33/35</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">100% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>23/23</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">97.3% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>36/37</span>
      </div>
    </div>
  </div>
  <div class='status-line high'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">99x</span>
<span class="cline-any cline-yes">119x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">7x</span>
<span class="cline-any cline-yes">65x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">23x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">7x</span>
<span class="cline-any cline-yes">32x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">28x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">7x</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">7x</span>
<span class="cline-any cline-yes">23x</span>
<span class="cline-any cline-yes">48x</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-yes">28x</span>
<span class="cline-any cline-yes">55x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">458x</span>
<span class="cline-any cline-yes">458x</span>
<span class="cline-any cline-yes">456x</span>
<span class="cline-any cline-yes">388x</span>
<span class="cline-any cline-yes">356x</span>
<span class="cline-any cline-yes">149x</span>
<span class="cline-any cline-yes">136x</span>
<span class="cline-any cline-yes">122x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">207x</span>
<span class="cline-any cline-yes">83x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">291x</span>
<span class="cline-any cline-yes">335x</span>
<span class="cline-any cline-yes">123x</span>
<span class="cline-any cline-yes">52x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">7x</span>
<span class="cline-any cline-yes">108x</span>
<span class="cline-any cline-yes">108x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">7x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">// Argument validation
const isValidObjectWith = fields =&gt; obj =&gt;
  !!obj &amp;&amp; !Array.isArray(obj) &amp;&amp; fields.every(field =&gt; obj.hasOwnProperty(field))
&nbsp;
const isValidAction = obj =&gt; {
  return isValidObjectWith(['message', 'func'])(obj) &amp;&amp;
    typeof obj.func === 'function' &amp;&amp; typeof obj.message === 'string'
}
&nbsp;
const isValidActionsArray = arr =&gt; arr.every(isValidAction)
&nbsp;
const isValidPostParams = obj =&gt; {
  return isValidObjectWith(['message', 'args'])(obj) &amp;&amp;
    Array.isArray(obj.args) &amp;&amp; typeof obj.message === 'string'
}
&nbsp;
const isValidPostParamsArray = arr =&gt; arr.every(isValidPostParams)
&nbsp;
const isValidObjectsArray = arr =&gt; (fields = []) =&gt;
  arr.every(isValidObjectWith(fields))
&nbsp;
const testArray = {
  'actionsArray': arr =&gt; isValidActionsArray(arr),
  'arraysArray': arr =&gt; arr.every(item =&gt; Array.isArray(item)),
  'objectsArray': arr =&gt; isValidObjectsArray(arr)(),
  'postParamsArray': arr =&gt; isValidPostParamsArray(arr),
  'stringsArray': arr =&gt; arr.every(item =&gt; typeof item === 'string')
}
&nbsp;
const isValidArg = arg =&gt; type =&gt; {
  if (type === 'null') return arg === null
  if (type === 'undefined') return arg === undefined
  if (type === 'action') return isValidAction(arg)
  if (Array.isArray(arg)) {
    if (type !== 'array' &amp;&amp; !testArray[type]) return false
    if (type === 'array') return true
    return testArray[type](arg)
  }
  if (arg) return typeof arg === type.toString() // eslint-disable-line
  return false
}
&nbsp;
const isValid = argument =&gt; (types = <span class="branch-0 cbranch-no" title="branch not covered" >null)</span> =&gt; {
  if (Array.isArray(types)) return types.some(type =&gt; isValidArg(argument)(type))
  if (isValidArg(argument)(types)) return true
  return false
}
&nbsp;
// Argument error builder
const argumentError = ({ expected = '', received, extraInfo = '' }) =&gt; {
  try {
    return new TypeError(`${'You should provide ' + expected}${'\n' + extraInfo}${'\nReceived: ' + JSON.stringify(received)}`)
  } catch (err) {
    <span class="missing-if-branch" title="else path not taken" >E</span>if (err.message === 'Converting circular structure to JSON') {
      return new TypeError(`${'You should provide ' + expected}${'\n' + extraInfo}${'\nReceived a circular structure: ' + received}`)
    }
<span class="cstat-no" title="statement not covered" >    throw err</span>
  }
}
&nbsp;
// Response builder
const makeResponse = work =&gt; `
  self.onmessage = event =&gt; {
    const args = event.data.message.args
    if (args) {
      self.postMessage((${work}).apply(null, args))
      return close()
    }
    self.postMessage((${work})())
    return close()
  }
`
&nbsp;
export {
  makeResponse,
  argumentError,
  isValid
}
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Mon May 22 2017 00:02:25 GMT-0300 (-03)
</div>
</div>
<script src="prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="sorter.js"></script>
</body>
</html>
